home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Comm / tcp / JabberwockySRC.lha / Jabberwocky / src / tools / brush2pix.c
Encoding:
C/C++ Source or Header  |  2002-04-24  |  3.7 KB  |  162 lines

  1. /*
  2. ** This little program can be used to convert an ILBM brush
  3. ** to something that MUI's Bodychunk class can understand.
  4. **
  5. ** Perfect for about logos and stuff like that...
  6. **
  7. ** Have fun,
  8. ** Stefan.
  9. **
  10. ** modified by Madcat for generating muidefpix structs
  11. */
  12.  
  13. /*
  14.  * The license status of this file is unknown :-( 
  15.  * Madcat has given Tom Parker and Matthias Munch all rights to his changes,
  16.  * What about about Stefan? This is probably Stefan Stuntz, author of MUI.
  17.  */
  18.  
  19. #include "exec/types.h"
  20. #include "exec/memory.h"
  21. #include "libraries/dos.h"
  22. #include "libraries/iffparse.h"
  23. #include "datatypes/pictureclass.h"
  24. #include "graphics/gfx.h"
  25. #include "proto/dos.h"
  26. #include "proto/iffparse.h"
  27. #include "stdlib.h"
  28. #include "string.h"
  29. #include "stdio.h"
  30. #include "ctype.h"
  31.  
  32.  
  33. #define to32(c) (((c)<<24)|((c)<<16)|((c)<<8)|(c))
  34.  
  35. #define ID_ANIM MAKE_ID('A','N','I','M')
  36. #define ID_ANHD MAKE_ID('A','N','H','D')
  37. #define ID_DLTA MAKE_ID('D','L','T','A')
  38.  
  39.  
  40. char name[101],uname[100];
  41.  
  42.  
  43. BOOL ParseILBM(struct IFFHandle *iff)
  44. {
  45.     struct StoredProperty *sp;
  46.     struct BitMapHeader *bmhd;
  47.     UBYTE *body;
  48.     int size,i;
  49.     UBYTE *cols;
  50.     BOOL rc = FALSE;
  51.  
  52.     if (!PropChunk(iff,ID_ILBM,ID_BMHD) &&
  53.         !PropChunk(iff,ID_ILBM,ID_CMAP) &&
  54.         !StopChunk(iff,ID_ILBM,ID_BODY) &&
  55.         !StopOnExit(iff,ID_ILBM,ID_FORM) &&
  56.         !ParseIFF(iff,IFFPARSE_SCAN))
  57.     {
  58.         printf("/*\n** %s default pix\n*/\n\n", name);
  59.  
  60.         if (sp=FindProp(iff,ID_ILBM,ID_CMAP))
  61.         {
  62.             cols = (UBYTE *)sp->sp_Data;
  63.  
  64.             printf("const ULONG %s_colors[%ld] =\n{\n",name,sp->sp_Size);
  65.             for (i=0;i<sp->sp_Size;i+=3)
  66.                 printf("\t0x%08lx,0x%08lx,0x%08lx,\n",to32(cols[i]),to32(cols[i+1]),to32(cols[i+2]));
  67.             printf("};\n\n");
  68.         }
  69.  
  70.         if (sp=FindProp(iff,ID_ILBM,ID_BMHD))
  71.         {
  72.             bmhd = (struct BitMapHeader *)sp->sp_Data;
  73.  
  74.             if ((bmhd->bmh_Compression==cmpNone) || (bmhd->bmh_Compression==cmpByteRun1))
  75.             {
  76.                 size = CurrentChunk(iff)->cn_Size;
  77.  
  78.                 if (body=malloc(size))
  79.                 {
  80.                     if (ReadChunkBytes(iff,body,size)==size)
  81.                     {
  82.                         fprintf(stderr,"Width %d Height %d Depth %d - converting...\n",bmhd->bmh_Width,bmhd->bmh_Height,bmhd->bmh_Depth);
  83.  
  84.                         printf("#define %s_WIDTH       %3d\n",uname,bmhd->bmh_Width);
  85.                         printf("#define %s_HEIGHT      %3d\n",uname,bmhd->bmh_Height);
  86.                         printf("#define %s_DEPTH       %3d\n",uname,bmhd->bmh_Depth);
  87.                         printf("#define %s_COMPRESSION %3d\n",uname,bmhd->bmh_Compression);
  88.                         printf("#define %s_MASKING     %3d\n",uname,bmhd->bmh_Masking);
  89.                         printf("\n");
  90.  
  91.                         printf("const UBYTE %s_body[%ld] = {\n",name,size);
  92.                         for (i=0;i<size;i++)
  93.                         {
  94.                             printf("0x%02lx,",body[i]);
  95.                             if (!((i+1)%15)) printf("\n");
  96.                         }
  97.                         printf(" };\n");
  98.  
  99.                         rc = TRUE;
  100.                     }
  101.                     free(body);
  102.                 }
  103.             }
  104.         }
  105.  
  106.         printf("\nmuidefpix %s_defpix =\n{\n", name);
  107.         printf("\t%s_body,\n",name);
  108.         printf("\t%s_colors,\n",name);
  109.         printf("\t%s_WIDTH, %s_HEIGHT, %s_DEPTH,\n", uname, uname, uname);
  110.         printf("\t%s_COMPRESSION, %s_MASKING \n", uname, uname);
  111.         printf("};\n");
  112.     }
  113.     return(rc);
  114. }
  115.  
  116.  
  117. int main(int argc,char **argv)
  118. {
  119.     char *c;
  120.     struct IFFHandle *iff;
  121.     struct ContextNode *cn;
  122.  
  123.     if (argc<2 || argc>3 || argv[1][0]=='?')
  124.     {
  125.         printf("Syntax: %s ilbm-file\n",argv[0]);
  126.         exit(20);
  127.     }
  128.     
  129.     name[100] = 0;
  130.     strncpy(name,FilePart(argv[1]),100);
  131.     if (c=strchr(name,'.')) *c=0;
  132.     strcpy(uname,name);
  133.     for (c=uname;*c;c++)
  134.         *c=toupper(*c);
  135.  
  136.     if (iff=AllocIFF())
  137.     {
  138.         if (iff->iff_Stream=Open(argv[1],MODE_OLDFILE))
  139.         {
  140.             InitIFFasDOS(iff);
  141.  
  142.             if (!OpenIFF(iff,IFFF_READ))
  143.             {
  144.                 if (!ParseIFF(iff,IFFPARSE_STEP))
  145.                 {
  146.                     if ((cn=CurrentChunk(iff)) && (cn->cn_ID==ID_FORM))
  147.                     {
  148.                         if (cn->cn_Type==ID_ILBM)
  149.                         {
  150.                             ParseILBM(iff);
  151.                         }
  152.                     }
  153.                 }
  154.                 CloseIFF(iff);
  155.             }
  156.             Close(iff->iff_Stream);
  157.         }
  158.         FreeIFF(iff);
  159.     }
  160.     return(0);
  161. }
  162.